package com.ruicar.afs.cloud.afscase.channel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.afscase.channel.entity.ChannelRiskInfo;
import com.ruicar.afs.cloud.afscase.channel.feign.ChannelFeignService;
import com.ruicar.afs.cloud.afscase.channel.mapper.ChannelRiskInfoMapper;
import com.ruicar.afs.cloud.afscase.channel.service.ChannelRiskInfoService;
import com.ruicar.afs.cloud.afscase.channel.utils.CaseConfig;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Description: </p>
 *
 * @author mingzhi.li
 * @version 1.0
 * @date create on 2020-07-27 23:17
 */
@Service
@AllArgsConstructor
@Data
@Slf4j
public class ChannelRiskInfoServiceImpl extends ServiceImpl<ChannelRiskInfoMapper, ChannelRiskInfo> implements ChannelRiskInfoService {

    private final CaseConfig caseConfig;
    private final ChannelFeignService channelFeignService;

    /**
     * 优质等级有效期到期更新优质等级为：无
     *
     * @param channelRiskInfoList
     * @return
     */
    @Override
    public IResponse synchronousQualityLevelToChannel(List<ChannelRiskInfo> channelRiskInfoList) {
        //请求头
        Map<String, String> headers = new HashMap<>();
        //接口返回结果
        headers.put("clientId", caseConfig.getChannelClientId());
        headers.put("clientSecret", caseConfig.getChannelClientSecret());
        IResponse result = (IResponse) channelFeignService.synchronousQualityLevelToChannel(channelRiskInfoList, headers);
        //结果解析只有成功时，方可返回正确的值
        return IResponse.success(result);
    }
}
